package br.edu.unicentro.mymib.mbean;

import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

public class ValidateLoginMBean {

	private boolean validateUser;

	public ValidateLoginMBean() {
	}

	public boolean isValidateUser() {
		if (((HttpServletRequest) FacesContext.getCurrentInstance()
				.getExternalContext().getRequest()).isUserInRole("GRANTED")) {
			return true;
		}
		if (((HttpServletRequest) FacesContext.getCurrentInstance()
				.getExternalContext().getRequest()).isUserInRole("ADMIN")) {
			return true;
		}
		return false;
	}

	public String invalidateSession() {
		((HttpSession) FacesContext.getCurrentInstance().getExternalContext()
				.getSession(false)).invalidate();
		return "toHome";
	}

}
